﻿using System.Net.Mail;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 道具管理器
/// </summary>
public class PropController : BaseManager<PropController>
{
    GameObject propGameObj;
    List<FightProp> propList = new List<FightProp>();

    public List<FightProp> PropList { get => propList; set => propList = value; }

    public void CreatPropGameObj()
    {
        propGameObj = new GameObject("propGameObj");
        propGameObj.transform.position = Vector3.zero;
    }

    public void CreatProp(Vector3 endPos)
    {
        if (PlayerController.GetInstance().Player == null)
            return;
        endPos.Set(endPos.x, 0.05f, endPos.z);
        FightProp prop = new FightProp();
        PropList.Add(prop);
        prop.Obj.transform.SetParent(propGameObj.transform);
        prop.Obj.transform.position = new Vector3(PlayerController.GetInstance().Player.Obj.transform.position.x, 0.05f, PlayerController.GetInstance().Player.Obj.transform.position.z);
        Vector3 dir = new Vector3(endPos.x - prop.Obj.transform.position.x, 0, endPos.z - prop.Obj.transform.position.z);
        prop.SetMoveDIr(dir, endPos);
        prop.IsMove = true;
    }
    public void CreatDotProp(Vector3 start, Vector3 endPos)
    {
        endPos.Set(endPos.x, 0.05f, endPos.z);
        FightProp prop = new FightProp();
        PropList.Add(prop);
        prop.Obj.transform.SetParent(propGameObj.transform);
        prop.Obj.transform.position = new Vector3(start.x, 0.05f, start.z);
        Vector3 dir = new Vector3(endPos.x - prop.Obj.transform.position.x, 0, endPos.z - prop.Obj.transform.position.z);
        prop.SetMoveDIr(dir, endPos);
        prop.IsMove = true;
    }
    public void Recycle()
    {
        while (propList.Count > 0)
        {
            propList[0].ObjDestroy();
        }
    }
}
